﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class KhieuNaiController : Controller
    {
        //
        // GET: /KhieuNai/

        public ActionResult Index()
        {
            if (Session["tendangnhap"] == null || Session["tendangnhap"].ToString() == "")
            {
                return RedirectToAction("DangNhap", "TaiKhoan");
            }
            ViewBag.MenuClass = Session["MenuClass"];
            return View();
        }

        [HttpPost]
        public ActionResult Index(KhieuNaiModel khieuNaiModel)
        {
            DataClassesDataContext dataContext = new DataClassesDataContext();
            DonKhieuNai donKhieuNai = new DonKhieuNai();
            donKhieuNai.TieuDe = khieuNaiModel.tieuDe;
            donKhieuNai.NoiDung = khieuNaiModel.noiDung;
            donKhieuNai.Date = DateTime.Now.ToShortDateString();
            string tenDangNhap = Session["tendangnhap"].ToString();
            donKhieuNai.KhachHang_Id = (from user in dataContext.KhachHangs where user.UserName.Equals(tenDangNhap) select user.Id).FirstOrDefault();

            dataContext.DonKhieuNais.InsertOnSubmit(donKhieuNai);
            dataContext.SubmitChanges();
            return View();
        }

    }
}
